// Released in the Public Domain. http://creativecommons.org/licenses/publicdomain/
package org.xi8ix.async.spi;

import org.xi8ix.async.Peer;
import org.xi8ix.async.Tuner;
import org.xi8ix.async.Statistics;

import java.net.InetSocketAddress;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * Tracks the relavent information about a remote host.
 *
 * @author Iain Shigeoka
 */
abstract class AbstractPeer implements Peer {
    /** The address of the remote side of this virtual connection. */
    protected final InetSocketAddress address;
    protected Tuner tuner = new TunerImpl(1024);
    protected Statistics statistics = new StatisticsImpl();

    /**
     * SendFuture objects for new messages to be sent out.
     */
    private final Queue<SendFuture<AbstractPeer>> sendQueue = new ConcurrentLinkedQueue<SendFuture<AbstractPeer>>();

    public AbstractPeer(InetSocketAddress address) {
        this.address = address;
    }

    public InetSocketAddress getAddress() {
        return address;
    }
    
    /**
     * Return the statistics of this server's sender.
     *
     * @return the statistics associated with this server.
     */
    public Statistics getStatistics() {
        return statistics;
    }

    /**
     * Return the tuner associated with this server's sender.
     *
     * @return the statistics associated with this server.
     */
    public Tuner getTuner() {
        return tuner;
    }

    public Queue<SendFuture<AbstractPeer>> getSendQueue() {
        return sendQueue;
    }
}
